package database

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

var DB *gorm.DB

func InitDB() *gorm.DB {
	var err error

	dsn := "root:e4fc1c81f7b78285@tcp(10.168.30.15:3306)/release_teamones_saas?charset=utf8mb4&parseTime=True&loc=Local"
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})

	DB = DB.Session(&gorm.Session{Logger: logger.Default.LogMode(logger.Info)})

	if err != nil {
		fmt.Printf("clickhouse connect error %v", err)
	}

	if DB.Error != nil {
		fmt.Printf("database error %v", DB.Error)
	}

	return DB
}
